<?php

/**
 * Integrator actions.
 *
 * @package    mathematica
 * @subpackage Integrator
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 9301 2008-05-27 01:08:46Z dwhittle $
 */
class IntegratorActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */

  public function executeIndex($request)
  {
    if($request->isMethod('POST'))
  	{
  	  //set_time_limit(600);
  	  $configuracion = ConfigurationPeer::retrieveByPK(1);
  	  $x = $request->getParameter('x') ? $request->getParameter('x') : 0;
  	  $y = $request->getParameter('y') ? $request->getParameter('y') : 20;
//  	  Deb::print_r($configuracion->getFunctionColor());
  	  $back_color = $this->convert( $configuracion->getBackgroundColor() );
  	  $func_color = $this->convert( $configuracion->getFunctionColor() );
  	  
  	  $integrator = new Integrator($configuracion->getEjeX(),$configuracion->getEjeY(),$x,$y,$func_color[0],$func_color[1],$func_color[2],$back_color[0],$back_color[1],$back_color[2],$request->getParameter('expr'),$configuracion->getStep(),0);
  	  $integrator->drawFunctionAndShowIntegral();
  	  
  	}
  }
  
  public function executeConfiguration($request)
  {
  	$id = $request->getParameter('id');
  	$this->form = new ConfigurationForm(ConfigurationPeer::retrieveByPK($id));
    
    if($request->isMethod('POST'))
    {
       $this->form->bind($request->getParameter('configuration'));
        
       if ($this->form->isValid())
       {
         $configuration = $this->form->save();
         $this->redirect($this->redirect('@integration'));
       }
    }
  }
 public function convert( $color )
  {
	$rgb = array ();
	
	if ($color == 'NEGRO'){
		$rgb[0] = 0;
		$rgb[1] = 0;
		$rgb[2] = 0;
		
	}
	if ($color == 'VERDE'){
		$rgb[0] = 0;
		$rgb[1] = 255;
		$rgb[2] = 255;
		
	}	
	if ($color == 'AZUL'){
		$rgb[0] = 0;
		$rgb[1] = 0;
		$rgb[2] = 255;
		
	}
	if ($color == 'ROJO'){
		$rgb[0] = 255;
		$rgb[1] = 0;
		$rgb[2] = 0;
		
	}	
	if ($color == 'BLANCO'){
		$rgb[0] = 255;
		$rgb[1] = 255;
		$rgb[2] = 255;
	}
	return $rgb;

  }
}
